﻿using System;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using XcoAppSpaces.Security.Basic;
using XcoAppSpaces.Contracts.Security;
using System.Net;
using XcoAppSpaces.Security.None;

namespace test.XcoAppSpaces.Security.Basic
{
	[TestFixture]
	public class testXcoNoSecurityService
	{
		private string user1;
		private string pass1;

		private XcoNoSecurityService secService;
		
		[SetUp]
		public void SetUp()
		{
			user1 = "user1";
			pass1 = "pass1";

			secService = new XcoNoSecurityService();
		}

		[Test]
		public void TestInitialize()
		{
			secService.Initialize(null);
		}

		[Test]
		public void TestGetClientCredentials()
		{
			IXcoClientCredentials cred = secService.GetClientCredentials(new NetworkCredential(user1, pass1), null);
			Assert.AreEqual(user1, cred.User);
			Assert.AreEqual(PasswordUtil.CreatePasswordHash(pass1), cred.Password);
		}

		[Test]
		public void TestGetClientCredentials_NoUser()
		{
			IXcoClientCredentials cred = secService.GetClientCredentials(null, null);
			Assert.IsNull(cred);
		}

		[Test]
		public void TestGetClientCredentials_NoPassword()
		{
			IXcoClientCredentials cred = secService.GetClientCredentials(new NetworkCredential(user1, (string)null), null);
			Assert.AreEqual(user1, cred.User);
			Assert.IsNull(cred.Password);
		}


		[Test]
		public void TestAuthenticate()
		{
			XcoAuthenticationResult authResult = secService.Authenticate(null, null);
			Assert.IsTrue(authResult.IsAuthenticated);
			//Assert.IsTrue(authResult.CanAccessWorker);
			Assert.AreEqual(Guid.Empty, authResult.SessionID);
		}

		[Test]
		public void TestCheckPermission()
		{
			secService.CheckPermission(null, null, null, Guid.Empty);
		}
	}
}
